import { Component, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFRadioWidgetSchema, SFSchema, SFUISchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { SystemService } from '../../../services/system.service';

@Component({
  selector: 'app-basic-config-action-modal',
  templateUrl: './basic-config-action-modal.component.html',
  styleUrls: ['./basic-config-action-modal.component.less']
})
export class BasicConfigActionModalComponent implements OnInit {
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  i: any;
  schema!: SFSchema;
  ui: SFUISchema = {
    '*': {
      spanLabelFixed: 120,
      grid: { span: 24 }
    }
  };
  constructor(private modal: NzModalRef,public service: SystemService) {}

  ngOnInit(): void {
    this.initSF(this.i);
  }
  initSF(staff: any) {
    this.schema = {
      properties: {
        name: {
          title: '配置类型',
          type: 'string',
          enum: [
            { label: '全部', value: '全部' },
            { label: '企业认证审核', value: '企业认证审核' },
            { label: '企业管理员审核', value: '企业管理员审核' },
            { label: '用户实名认证审核', value: '用户实名认证审核' },
            { label: '司机实名认证审核', value: '司机实名认证审核' },
            { label: '司机驾驶证审核', value: '司机驾驶证审核' },
            { label: '车辆审核', value: '车辆审核' }
          ],
          ui: {
            widget: 'select',
            placeholder: '请选择',
            change: (i: any) => {
              this.sf.value.name = i;
              this.sf?.setValue('/name', i);
            }
          },
          default: staff.name
        },
        phone: {
          title: '配置项',
          type: 'string',
          ui: { placeholder: '请输入' },
          default: staff.phone
        },
        roleId: {
          type: 'string',
          title: '启用状态',
          enum: [
            { label: '启用', value: 1 },
            { label: '停用', value: 0 }
          ],
          ui: {
            widget: 'radio'
          } as SFRadioWidgetSchema,
          default: staff?.roleId || 1
        }
      },
      required: ['name', 'phone', 'roleId']
    };
  }

  sure() {
    if (this.i.id === 0) {
      const params: any = {
        ...this.sf.value,
        roleId: this.sf.value.roleId,
        telephone: this.sf.value.phone,
        staffName: this.sf.value.name
      };
      // this.service.request(this.service.$api_addStaff, params).subscribe((res) => {
      //   console.log(res);
      //   if (res) {
      //     this.service.msgSrv.success('保存成功！');
      //     this.modal.close(true);
      //   }
      //   // this.showInviteFlag = true;
      //   // this.inviteCode = res.inviteCode;
      // });
    } else {
      const params: any = {
        appUserId: this.i.appUserId,
        staffName: this.sf.value.name,
        roleId: this.sf.value.roleId,
        telephone: this.i.telephone
      };
    }
  }

  close() {
    this.modal.destroy();
  }
}
